package 抽象数据类型;

import 抽象数据类型.Bag;

/**
 * 无向图
 */
public class Graph {
    private int V;//顶点数目
    private int E;//边的数目
    private Bag<Integer>[] adj;//邻接表

    public Graph(int V) {
        this.V = V;
        this.E = 0;
        adj = new Bag[V];
        for (int v = 0; v < V; v++) {
            adj[v] = new Bag<>();
        }
    }

    public void addGraph(int[] v, int[] w) {
        for (int i = 0; i < w.length; i++) {
            addEdge(v[i], w[i]);
        }
    }

    public int V() {
        return V;
    }

    public int E() {
        return E;
    }

    public void addEdge(int v, int w) {
        adj[v].add(w);
        adj[w].add(v);
    }

    public Iterable<Integer> adj(int v) {
        return this.adj[v];
    }
}
